package com.mce.nebula.controller;

import com.mce.nebula.dto.ApiResponse;
import com.mce.nebula.service.PhpConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * PHP配置控制器
 * 对应Python的PhpConfigView
 */
@Slf4j
@RestController
@RequestMapping("/api/php")
@Tag(name = "PHP配置", description = "PHP环境配置相关接口")
@RequiredArgsConstructor
public class PhpConfigController {
    
    private final PhpConfigService phpConfigService;
    
    @GetMapping("/config")
    @Operation(summary = "获取PHP环境配置", description = "获取PHP版本和扩展配置信息")
    public ResponseEntity<ApiResponse<Map<String, Object>>> getPhpConfig() {
        try {
            Map<String, Object> phpConfig = phpConfigService.getPhpConfig();
            return ResponseEntity.ok(ApiResponse.success(phpConfig, "PHP配置获取成功"));
        } catch (Exception e) {
            log.error("Failed to get PHP config", e);
            return ResponseEntity.badRequest()
                .body(ApiResponse.error(400, e.getMessage()));
        }
    }
}
